package com.soft.mainsite.common.domain;/**
 * @(#)2019/4/23 10:43
 * <p>
 * Copyright HeNan soft. All rights reserved.
 */

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * <p>此类用于统一接口返回</p>
 * <p>@author:xuzhenjia</p>
 * <p>@date:2019/4/23</p>
 * <p>@remark</p>
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "RestResponse<T>", description = "响应通用参数包装")
public class RestResponse<T>{

    @ApiModelProperty("响应错误编码,0为正常")
    private int code;

    @ApiModelProperty("响应错误信息")
    private String msg;

    @ApiModelProperty("响应内容")
    private T result;

    public static <T> RestResponse<T> success() {
        return new RestResponse();
    }

    public static <T> RestResponse<T> success(T result) {
        RestResponse response = new RestResponse();
        response.setResult(result);
        return response;
    }

    public static <T> RestResponse<T> success(String msg, T result) {
        RestResponse response = new RestResponse();
        response.setResult(result);
        response.setMsg(msg);
        return response;
    }

    public static <T> RestResponse<T> success(int code, String msg, T result) {
        RestResponse response = new RestResponse();
        response.setResult(result);
        response.setMsg(msg);
        response.setCode(code);
        return response;
    }

    public RestResponse() {
        this(0, "");
    }

    public RestResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public RestResponse(int code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return this.result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    @Override
    public String toString() {
        return "RestResponse [code=" + this.code + ", msg=" + this.msg + ", result=" + this.result + "]";
    }
}
